import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '../layout'
 
//内网去掉
//import approvalsRouter from './modules/approvalsManage'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/404',
    component: () => import('@/pages/enterprise/views/error-page/404'),
    hidden: true
  },
  /*  {
    path: '/project-screen',
    component: () => import('@/pages/enterprise/views/screen/ProjectScreen.vue'),
    name: 'ProjectScreen',
    hidden: true
  },*/
  {
    path: '/401',
    component: () => import('@/pages/enterprise/views/error-page/401'),
    hidden: true
  },
  {
    path: '/tenancy',
    component: () => import('@/pages/enterprise/views/tenancy/index'),
    name: 'tenancy',
    hidden: true
  },
  {
    path: '/screen',
    component: () => import('@/pages/enterprise/views/screen/index'),
    name: 'screen',
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/createProject',
    meta: {
      icon: 'dashboard', roles: ['superSysOpsAdmin', 'entAdmin', 'proAdmin', 'formalEmployee']
    },
    children: [
      // {
      //   path: 'dashboard',
      //   // component: () => import('@/pages/enterprise/views/home/home.vue'),
      //   component: () => import('@/pages/enterprise/views/project/CreateProject.vue'),
      //   name: 'Dashboard',
      //   meta: { title: '首页', roles: ['superSysOpsAdmin', 'entAdmin', 'proAdmin', 'formalEmployee'], noCache: true }
      // }
      {
        path: 'createProject',
        component: () => import('@/pages/enterprise/views/project/CreateProject.vue'),
        name: 'CreateProject',
        meta: { title: '首页', roles: ['superSysOpsAdmin', 'entAdmin', 'proAdmin', 'formalEmployee'], noCache: true, affix: true 
        ,keepAlive: false // 设置为false会让页面不被缓存
        }
      }
    ]
  },
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/pages/enterprise/views/profile/index'),
        name: 'Profile',
        meta: { title: 'profile', icon: 'user', noCache: true }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [

  {
    path: '/project',
    component: Layout,
    redirect: '/project/manage',
    name: 'project',
    alwaysShow: true,
    meta: {
      title: '项目管理',
      icon: 'icon-xmxi', roles: ['superSysOpsAdmin', 'entAdmin', 'proAdmin', 'formalEmployee']
      ,keepAlive: false // 设置为false会让页面不被缓存
    },
    children: [
      //内网去除
      // {
      //   path: 'initiateProject',
      //   component: () => import('@/pages/enterprise/views/project/InitiateProject.vue'),
      //   name: 'InitiateProject',
      //   meta: { title: '项目发起', roles: ['superSysOpsAdmin', 'entAdmin', 'formalEmployee'], noCache: true }
      // },
      {
        path: 'projectList',
        component: () => import('@/pages/enterprise/views/project/ProjectList.vue'),
        name: 'ProjectList',
        meta: { title: '创建项目', roles: ['superSysOpsAdmin', 'entAdmin'], noCache: true }
        ,keepAlive: false // 设置为false会让页面不被缓存
      },
      //内网去除
      // {
      //   path: 'planProject',
      //   component: () => import('@/pages/enterprise/views/project/project_plan.vue'),
      //   name: 'ProjectManage',
      //   meta: { title: '项目计划', roles: ['superSysOpsAdmin', 'entAdmin', 'formalEmployee'], noCache: true }
      // }

    ]
  },
  {
    path: '/personnel',
    component: Layout,
    redirect: '/personnel/manage',
    name: 'Personnel',
    alwaysShow: true,
    meta: {
      title: '人员管理',
      icon: 'icon-xmxi',
      noCache: true, roles: ['superSysOpsAdmin', 'entAdmin', 'formalEmployee']
    },
    children: [
      {
        path: 'manage',
        component: () => import('@/pages/enterprise/views/Personnel/member-manage.vue'),
        name: 'ProjectManage',
        meta: { title: '公司成员', roles: ['superSysOpsAdmin', 'entAdmin', 'formalEmployee'], noCache: true }
      },
      //内网去除
      // {
      //   path: 'positionManage',
      //   component: () => import('@/pages/enterprise/views/Personnel/position-manage.vue'),
      //   name: 'ProjectManage',
      //   meta: { title: '岗位管理', roles: ['superSysOpsAdmin', 'entAdmin', 'formalEmployee'], noCache: true }
      // },
       
    ]
  },
  {
    path: '/video',
    component: Layout,
    redirect: '/video/manage',
    name: 'project',
    meta: {
      title: '视频管理',
      icon: 'video-gl',
      noCache: true, roles: ['entAdmin']
    },
    children: [
      {
        path: 'manage',
        component: () => import('@/pages/enterprise/views/video/video-manage1.vue'),
      
        name: 'VideoManage',
        meta: { title: '视频管理',   noCache: true }
        
      }
    ]
  },
  {
    path: '/video',
    component: Layout,
    redirect: '/video/manage',
    name: 'project',
    meta: {
      title: '视频管理',
      icon: 'video-gl',
      noCache: true, roles: ['superSysOpsAdmin']
    },
    children: [
      {
        path: 'manage',
        component: () => import('@/pages/enterprise/views/video/video-manage.vue'),
      
        name: 'VideoManage',
        meta: { title: '视频管理',   noCache: true }
        
      }
    ]
  },

  {
    path: '/device',
    component: Layout,
    redirect: '/device/facility',
    name: 'Alarm',
    meta: {
      title: '智能终端',
      icon: 'sbgl',
    
        keepAlive: false // 设置为false会让页面不被缓存
     
    },
    children: [
      {
        path: 'facility',
        component: () => import('@/pages/enterprise/views/equipment/facility-manage.vue'),
        name: 'FacilityManage',
        meta: { title: '设备管理', noCache: true   ,keepAlive: false // 设置为false会让页面不被缓存 
      }
      },
      {
        path: 'manage',
        component: () => import('@/pages/enterprise/views/gateway/gateway-manage.vue'),
        name: 'GatewayManage',
        meta: { title: '网关管理', noCache: true  ,keepAlive: false // 设置为false会让页面不被缓存 
      }
      },
      {
        path: 'equipment',
        component: () => import('@/pages/enterprise/views/gateway/gateway-equipment-manage.vue'),
        name: 'GatewayEquipmentManage',
        meta: { title: '网关关联设备', noCache: true ,  keepAlive: false // 设置为false会让页面不被缓存
      }
      }
    ]
  },
  // {
  //   path: '/gateway',
  //   component: Layout,
  //   redirect: '/gateway/manage',
  //   name: 'gateway',
  //   meta: {
  //     title: '网关管理',
  //     icon: 'wggl'
  //   },
  //   children: [
  //     {
  //       path: 'manage',
  //       component: () => import('@/pages/enterprise/views/gateway/gateway-manage.vue'),
  //       name: 'GatewayManage',
  //       meta: { title: '网关信息管理', noCache: true }
  //     },
  //     {
  //       path: 'equipment',
  //       component: () => import('@/pages/enterprise/views/gateway/gateway-equipment-manage.vue'),
  //       name: 'GatewayEquipmentManage',
  //       meta: { title: '网关关联设备管理', noCache: true }
  //     }
  //   ]
  // },
  {
    path: '/crafts',
    component: Layout,
    redirect: '/crafts/manage',
    name: 'crafts',
    alwaysShow: true,
    meta: {
      title: '项目资料库',
      icon: 'icon-gongymanage',
      noCache: true, roles: ['superSysOpsAdmin', 'entAdmin', 'proAdmin', 'formalEmployee']
    },
    children: [
      {
        path: 'contract',
        component: () => import('@/pages/enterprise/views/crafts/crafts-info-manage.vue'),
        name: 'ContractManage',
        meta: { title: '工艺管理', roles: ['superSysOpsAdmin', 'entAdmin', 'proAdmin', 'formalEmployee'], noCache: true }
      },
      {
        path: 'repair',
        component: () => import('@/pages/enterprise/views/repair/repair-mode-manage.vue'),
        name: 'RepairMode',
        meta: { title: '生产计划管理', roles: ['superSysOpsAdmin', 'entAdmin', 'proAdmin', 'formalEmployee'], noCache: true }
      },
      // {
      //   path: 'hotworkplan',
      //   component: () => import('@/pages/enterprise/views/hotworkplan/index.vue'),
      //   name: 'HotworkplanManage',
      //   meta: { title: '方案录入', noCache: true }
      // }
    ]
  },
  // {
  //   path: '/hotworkplan',
  //   component: Layout,
  //   redirect: '/hotworkplan',
  //   name: 'hotworkplan',
  //   alwaysShow: true,
  //   meta: {
  //     title: '动火方案',
  //     icon: 'dhfa'
  //   },
  //   children: [
  //     {
  //       path: 'hotworkplan',
  //       component: () => import('@/pages/enterprise/views/hotworkplan/index.vue'),
  //       name: 'HotworkplanManage',
  //       meta: { title: '动火方案', noCache: true }
  //     }
  //   ]
  // },
//内网去掉
 // approvalsRouter,
 

  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  base: 'enterprise',
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
